package com.example.demo.leetcode.classics150;

import java.util.Arrays;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _10跳跃游戏II
 * @description
 * @date 2023/07/11 15:56
 * <p>
 * ******************************************************
 */
public class _10跳跃游戏II {

    public int jump(int[] nums) {
        int length = nums.length;
        int[] dp = new int[length];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 1; i < length; i++) {
            for (int j = 0; j < i; j++) {
                int num = nums[j];
                if (num >= (i - j)) {
                    dp[i] = Math.min(dp[i], dp[j] + 1);
                    break;
                }
            }
        }

        return dp[length - 1];
    }
}
